package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.ErpAccountingDto;
import com.nuoniu.sibanyun.entity.dto.ErpAccountingSearchDto;
import com.nuoniu.sibanyun.entity.vo.ErpAccountingVo;
import com.nuoniu.sibanyun.service.erp.IErpAccountingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会计科目表 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-25
 */
@RestController
@RequestMapping("/erp/accounting")
@Api(value = "会计科目表", tags = "会计科目表")
public class ErpAccountingController extends BaseController {

    @Autowired
    private IErpAccountingService erpAccountingService;


    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public HttpResult<List<ErpAccountingVo>> page(Page page, ErpAccountingSearchDto erpAccountingSearchDto) {
        return HttpResult.ok(erpAccountingService.page(page, erpAccountingSearchDto));
    }


    @GetMapping("/listByTypeId")
    @ApiOperation(value = "通过 会计科目分类Id 第一级获取会计科目")
    public HttpResult<List<ErpAccountingVo>> listFirstLevelErpAccountingByTypeId(Integer typeId) {
        return HttpResult.ok(erpAccountingService.listFirstLevelErpAccountingByTypeId(typeId));
    }

    @GetMapping("/listByParentId")
    @ApiOperation(value = "根据 父级ID查询 下级科目")
    public HttpResult<List<ErpAccountingVo>> listErpAccountingByParentId(Integer parentId) {
        return HttpResult.ok(erpAccountingService.listErpAccountingByParentId(parentId));
    }

    @GetMapping("/listCurrentAll")
    @ApiOperation(value = "获取当前租户 所有的会计科目")
    public HttpResult<List<ErpAccountingVo>> listCurrentAll() {
        return HttpResult.ok(erpAccountingService.listCurrentAll());
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增/编辑")
    public HttpResult saveOrUpdateOne(@RequestBody ErpAccountingDto erpAccountingDto) {
        erpAccountingService.saveOrUpdateOne(erpAccountingDto);
        return HttpResult.ok();
    }

    @DeleteMapping("batchDelete")
    @ApiOperation(value = "科目删除")
    public HttpResult batchDeleteByIds(Long id) {
        erpAccountingService.batchDeleteByIds(id);
        return HttpResult.ok();
    }

    @GetMapping("/getOneByCondition")
    @ApiOperation(value = "通过ID获取某个会计科目的数据")
    public HttpResult getOneByCondition(Integer actionType,Long currentId) {
        return HttpResult.ok(erpAccountingService.getOneByCondition(actionType, currentId));
    }

    @GetMapping("getDetail")
    @ApiOperation("获取详情")
    public HttpResult getDetail(Long id) {
        return HttpResult.ok(erpAccountingService.getById(id));
    }

}
